#!/bin/bash

set -eux

if [ $# -ne 2 ]
then
    echo "Usage: $0 <dir> <bigfile>"
    exit 2
fi

DIR=$1
BIGFILE=$2
hg clone -U . "$DIR"
hg -R "$DIR" verify
rm -r "$DIR" || true
hg clone -U ../anacrolix "$DIR"
hg -R "$DIR" verify
cp -n "$BIGFILE" -t "$DIR"
test    "$(md5sum "$BIGFILE" | cut -d ' ' -f 1)" = \
        "$(md5sum "$DIR/$(basename "$BIGFILE")" | cut -d ' ' -f 1)"
rm -r "$DIR" || true
sleep 1
df -h
